<script src="{{ getAssets }}js/amazeui.datatables.min.js?v={{ assets_version }}"></script>
<script>
    var page_type = 'extract';  //设置页面名称
	var tables = $('#dataTables').DataTable({
		"sAjaxSource" : '{{ urlfor "RetailController.DataGrid"}}'
		,"bLengthChange": false
		,"fnServerData" : function(sSource, aoData, fnCallback) {
			var queryParams = checkQueryTableData(aoData);
            var form = $('#search-form').serializeArray();
            $.each(form, function(i, value){
                queryParams[value.name] = value.value;
            });
			$.post(sSource, JSON.stringify(queryParams),function(resp) {
				fnCallback(resp);
			},'json')
		}
		,columns: [
            {"bSortable": false, render:function(data, type, full, meta) {
                    return full.Archives.Realname;
            }}
            ,{"bSortable": false, render:function(data, type, full, meta) {
                    return full.Archives.Mobile;
            }}
            ,{"bSortable": false, render:function(data, type, full, meta) {
                    return full.BusinessName;
            }}
            ,{"bSortable": false, render:function(data, type, full, meta) {
                    return full.TotalMoney;
            }}
            ,{"bSortable": false, render:function(data, type, full, meta) {
                    return full.SumPayable;
            }}
            ,{"bSortable": false, render:function(data, type, full, meta) {
                    return full.AlreadyMoney;
             }}
			,{"bSortable": false, render:function(data, type, full, meta) {
			    if(full.PickUpType == 1) {
			        return '现场取镜';
                }else if(full.PickUpType == 2) {
                    return '邮递取镜';
                }else if(full.PickUpType == 3) {
                    return '指定时间取货';
                }
			}}
            ,{"bSortable": false, render:function(data, type, full, meta) {
                    return timetrans(full.CreatedAt);
            }}
            ,{"bSortable": false, render:function(data, type, full, meta) {
                    return full.HopePickUpTime ? timetransDate(full.HopePickUpTime) : '';
                }}
            ,{"bSortable": false, render:function(data, type, full, meta) {
                    var d = [];
                    d.push('<div class="am-text-left">');
                    switch (full.IsPayment) {
                        case 1:
                            d.push('<div class="am-text-sm">待付款 </div>');
                            break;
                        case 2:
                            d.push('<div class="am-text-sm">待取货</div>');
                            break;
                        case 3:
                            d.push('<div class="am-text-sm">部分退货</div>');
                            break;
                        case 4:
                            d.push('<div class="am-text-sm">已退货</div>');
                            break;
                        case 5:
                            d.push('<div class="am-text-sm">已完成</div>');
                            break;
                    }
                    d.push('</div>');
                    return d.join('');
                }}
			,{   
				"mDataProp": "Action", 
				"bSortable": false, 
				"sWidth":"6%",
				"render": function ( data, type, full, meta ) {
                    var d = [];
                    d.push('<a href="javascript:;" data-retid="'+ full.Id +'" data-pickuptype="'+ full.PickUpType +'" onclick="return popWindView(this);">取镜记录</a>');
                    return d.join('');
				}  
			 } 
		]
		,"aLengthMenu":[20, 50, 100, 200]
		,'bLengthChange': true
		,"serverSide": true
		,"bPaginate" : true
		,"bFilter" : false	//是否启动过滤、搜索功能 
		,"bInfo" : true //是否显示页脚信息，DataTables插件左下角显示记录数
		,"bProcessing" : true //DataTables载入数据时，是否显示‘进度’提示  
		  
	});
	$('#query-submit').click(function(){
        $("#dataTables").dataTable().fnDraw(false);

    });
	function reloadTable() {
		$("#dataTables").dataTable().fnDraw(false);
	}

	function dialogReback() {
		reloadTable();
	}
	
	$('#refresh').click(function(){
		reloadTable();
		return false;
	});
    function popWindView(obj) {
	    var o = $(obj);
        var sales_id = o.data('retid');
        layer.open({
            type: 2
            , title: '取镜记录'
            , shadeClose: true
            , shade: 0.2
            , id: 'search_retail_view_dialog'
            , area: ['1000px', "80%"]
            , content: ['{{ urlfor "RetailController.PickUpGoodsList" }}' + '?sales_id='+ sales_id]
            , anim: 1 //动画类型
            ,cancel: function(index, layero){
                layer.close(index);
                return false;
            }
        });
    }
</script>